import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-03-30
 * Time: 14:35
 */
public class Main {

    public static void main(String[] args) {
        Student[] students = {
                new Student("张三", 20, 88.5),
                new Student("李四", 19, 92.0),
                new Student("王五", 22, 85.0),
                new Student("赵六", 25, 96.5)
        };
        System.out.println("-- 自然排序（年龄升序）--");
        Arrays.sort(students); // 使用Comparable
        print(students);

        System.out.println("\n-- 自定义排序（成绩降序）--");
        Arrays.sort(students, new ScoreComparator()); // 使用Comparator
        print(students);
    }

    public static void print(Student[] students) {
        for (Student s : students) {
            System.out.println(s);// 自动调用toString()方法
        }
    }
}
/*
运行：
        -- 自然排序（年龄）--
        [李四|19|92.0]
        [张三|20|88.5]
        [王五|22|85.0]
        [赵六|25|96.5]

        -- 自定义排序（成绩）--
        [赵六|25|96.5]
        [李四|19|92.0]
        [张三|20|88.5]
        [王五|22|85.0]
*/
